package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.result.R;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.vo.UserInfoSearchVO;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-01-04
 */
@RestController

@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {

    @Resource
    UserInfoService userInfoService;


    @ApiOperation("锁定解锁会员")
    @PutMapping("/lock/{id}/{type}")
    public R lock(@PathVariable("id")String id,
                  @PathVariable("type")Integer type){
        userInfoService.update(Wrappers.lambdaUpdate(UserInfo.class)
                .eq(UserInfo::getId , id)
                .set(UserInfo::getStatus , type));
        return R.ok();
    }

    @ApiOperation("带条件的分页查询")
    @GetMapping("list/{pageNum}/{pageSize}")
    public R list(UserInfoSearchVO userInfoSearchVO ,
                  @PathVariable("pageNum")Integer pageNum,
                  @PathVariable("pageSize") Integer pageSize){
        Page<UserInfo>  page = userInfoService
                .listPage(userInfoSearchVO,pageNum,pageSize);
        return R.ok().data("page" , page);
    }


    @ApiOperation("查询所有")
    @GetMapping
    public R listAll(){
        return R.ok().data("items" , userInfoService.list());
    }
    @ApiOperation("根据id查询")
    @GetMapping("{id}")
    public R getById(@PathVariable("id")String id){
        return R.ok().data("item" , userInfoService.getById(id));
    }
    @ApiOperation("根据id删除")
    @DeleteMapping("{id}")
    public R removeById(@PathVariable("id")String id){
        userInfoService.removeById(id);
        return R.ok();
    }
//    @ApiOperation("新增")
//    @PostMapping
//    public R save(@RequestBody UserInfo userInfo){
//        userInfoService.removeById(id);
//        return R.ok();
//    }
}

